/*********************************
填报审核
* */
<template>
  <basic-container>
    <el-row>
      <targetExaminHead :sign="{g:true}" />
    </el-row>
    <el-row v-if="!isPlanSummary">
      <el-row style="margin:25px 0 0 0 ;">
        <div :height="searchheight">
          <span
            style="float:right;margin-top: -30px;cursor: pointer;"
            @click="searchchangeadvanced"
          >
            {{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
            <i
              :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
            />
          </span>
          <div v-show="searchadvanced">
            <el-form
              :inline="true"
              :model="searchForm"
              @keyup.enter.native="getDataList()"
              class="form-inline"
            >
              <el-form-item label="考核对象">
                <el-input v-model="searchForm.assessRealName" placeholder="考核对象" :clearable="true"></el-input>
              </el-form-item>
              <el-form-item label="考核名称">
                <el-input v-model="searchForm.name" placeholder="考核名称" :clearable="true"></el-input>
              </el-form-item>
              <el-form-item label="考核周期">
                <selectSearch @getDataByPerid="getDataByPerid"></selectSearch>
              </el-form-item>
              <el-form-item>
                <el-button
                  icon="el-icon-search"
                  type="primary"
                  class="marginLeft"
                  @click="getDataList(7)"
                >检索</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </el-row>
      <el-row>
        <div style="height: 50px; border-bottom: 1px solid #b0bde2">
          <div class="pull-right">
            <el-button plain type="primary" @click="proposedSummary">批量查看</el-button>
            <el-button plain type="primary" @click="submit(0)" :disabled="isAgreeOrNot">同意</el-button>
            <el-button plain type="primary" @click="submit(1)" :disabled="isAgreeOrNot">驳回</el-button>
          </div>
        </div>
      </el-row>
      <div style="margin:20px 0 0 0 ">
        <span>指标考核&nbsp;&nbsp;</span>
        <el-radio-group v-model="choosePerOrDept" @change="choosePerOrDeptChange">
          <el-radio :label="0">人员</el-radio>
          <el-radio :label="1">机构</el-radio>
        </el-radio-group>
      </div>
      <el-row>
        <el-table
          style="width: 100%;margin-top:20px"
          :data="dataList"
          border
          stripe
          ref="tableRef"
          header-align="center"
          v-loading="dataListLoading"
          @selection-change="handleSelectionChange"
        >
          <el-table-column :selectable="checkboxSelect" type="selection" width="55"></el-table-column>
          <el-table-column type="index" header-align="center" align="center" label="序号" width="55"></el-table-column>
          <el-table-column
            prop="assessUserName"
            align="center"
            label="员工编号"
            show-overflow-tooltip
            v-if="!choosePerOrDept"
          ></el-table-column>
          <el-table-column
            prop="assessRealName"
            align="center"
            label="考核对象"
            show-overflow-tooltip
            v-if="!choosePerOrDept"
          >
            <template slot-scope="scope">
              <span
                @click="examine(scope.row)"
                style="color:rgb(14, 37, 140);cursor:pointer"
              >{{scope.row.assessRealName}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="assessRealName"
            align="center"
            label="考核对象"
            show-overflow-tooltip
            v-else
          >
            <template slot-scope="scope">
              <span
                @click="examine(scope.row)"
                style="color:rgb(14, 37, 140);cursor:pointer"
              >{{scope.row.assessDeptName}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="assessDeptName"
            align="center"
            label="部门"
            show-overflow-tooltip
            v-if="!choosePerOrDept"
          ></el-table-column>
          <el-table-column prop="itemNum" align="center" label="指标数量" show-overflow-tooltip></el-table-column>
          <el-table-column prop="name" align="center" label="考核名称" show-overflow-tooltip></el-table-column>
          <el-table-column prop="period" align="center" label="考核周期" show-overflow-tooltip></el-table-column>
          <el-table-column prop="state" align="center" label="状态" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.state | transTargetState}}</span>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageData.pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageData.pageSize"
            :total="pageData.totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper"
          ></el-pagination>
        </div>
      </el-row>
    </el-row>
    <!-- 拟定汇总 -->
    <el-row v-if="isPlanSummary">
      <TianBaoTable
        v-if="isPlanSummary == true"
        ref="tianbaotable"
        :tianBaoTable="tianBaoTable"
        :ids="ids"
        :radio="radio"
        @fnBackOldPage="fnBackOldPage"
        :taskIds="taskIds"
      ></TianBaoTable>
    </el-row>
    <examinView
      v-if="examinVisible"
      ref="examinNode"
      @closeDialog="closeDialog1"
      @refreshDataList="getDataList"
    />
  </basic-container>
</template>

<script>
import targetExaminHead from "@/views/dailyExamine/components/targetExaminHead"; //状态头
import TianBaoTable from "./htndhuizong-table.vue";
import {
  examineList,
  indexExaminList,
  taskList
} from "@/api/dailyExamine/targetExamine/createAssessment"; //接口api

import examinView from "./examinView.vue";

import { jgtbshSubmit } from "@/api/dailyExamine/targetExamine/InitiateFilling";
import selectSearch from "@/views/dailyExamine/components/select-search.vue"; //流程组件

export default {
  data() {
    return {
      examinVisible: false,
      choosePerOrDept: 0,
      isAgreeOrNot: true,
      tianBaoTable: {},
      ids: [],
      radio: "1",
      taskIds: [],
      isPlanSummary: false,
      deptVisible: false, //机构考核组件显隐
      searchheight: "0", //搜索组件的高度
      searchadvanced: true, //搜索的显隐
      searchForm: {}, //搜索对象
      dataListLoading: false, //表格是否加载
      dataList: [], //表格数组
      multipleSelection: [], //勾选数据
      pageData: {
        //分页对象
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0
      },
      isEnd: true
    };
  },
  watch: {
    multipleSelection: {
      handler(val) {
        if (val.length == 0) {
          this.isAgreeOrNot = true;
        } else {
          this.isAgreeOrNot = false;
        }
      }
    }
  },
  components: {
    examinView,
    TianBaoTable,
    targetExaminHead, //状态头.
    selectSearch//搜索栏目下拉组件
  },
  filters: {},
  created() {
    this.getDataList();
  },
  methods: {
    // 关闭审核弹窗
    closeDialog1() {
      this.examinVisible = false;
    },
    // 点击名字
    examine(data) {
      this.examinVisible = true;
      this.$nextTick(() => {
        this.$refs.examinNode.init(data);
      });
    },
    choosePerOrDeptChange(val) {
      this.searchForm = {};
      this.dataList = [];
      this.getDataList();
    },
    checkboxSelect(row, rowIndex) {
      return true;
    },

    fnBackOldPage(data) {
      this.isPlanSummary = false;
      this.ids = [];
      this.multipleSelection = [];
      this.getDataList();
    },
    // 拟定汇总
    proposedSummary() {
      if (this.multipleSelection.length == 0) {
        this.$message.warning("请先选择数据");
      } else {
        this.isPlanSummary = true;
        this.tianBaoTable = {
          lastPage: "zbnd"
        };
      }
    },

    // 提交
    submit(type) {
      if (this.multipleSelection.length == 0) {
        this.$message.warning("请先选择要提交的数据");
      } else {
        var rows = this.$refs.tableRef.selection;
        if (rows.length == 0) {
          rows = this.$refs.tableRef.data;
        }

        this.$confirm(`确定批量${type == 0 ? "同意" : "驳回"}吗?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(res => {
            console.log("同意or驳回");
            //提交
            if (type == 0) {
              var params = {
                rows: rows,
                type: 0
              };
              jgtbshSubmit(params)
                .then(res => {
                  this.$message.closeAll();
                  this.$message({
                    type: "success",
                    message: "提交成功!"
                  });
                  this.getDataList();
                })
                .catch(() => {
                  this.$message({
                    type: "error",
                    message: "提交失败!"
                  });
                  this.getDataList();
                });
            }
            //驳回
            if (type == 1) {
              var params = {
                rows: rows,
                type: 1
              };
              jgtbshSubmit(params)
                .then(res => {
                  this.$message({
                    type: "success",
                    message: "驳回成功!"
                  });
                  this.getDataList();
                })
                .catch(() => {
                  this.$message({
                    type: "error",
                    message: "提交失败!"
                  });
                  this.getDataList();
                });
            }
          })
          .catch(() => {
            console.log("取消");
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
      }
    },
    // 查询条件的展开关闭
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if (this.searchadvanced) {
        this.searchheight = "auto";
      }
    },
    // 查询列表
    getDataList() {
      ////
      this.dataListLoading = true;
      taskList(
        Object.assign(
          {
            current: this.pageData.pageIndex,
            size: this.pageData.pageSize,
            type: this.choosePerOrDept
          },
          this.searchForm
        ),
        7
      )
        .then(r => {
          if (r.data.code == 0) {
            this.dataListLoading = false;
            this.dataList = r.data.data.records.map(it => {
              it.rowshows = true;
              return it;
            });
            this.pageData.totalPage = r.data.data.total;
          }
        })
        .catch(err => {});
    },

    // 勾选数据
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.ids = val.map(it => {
        return it.id;
      });
      this.taskIds = val.map(it => {
        return it.taskId;
      });
      if (val[0].type == 0) {
        this.radio = 1;
      } else {
        this.radio = 2;
      }
    },
    // 条数变化
    sizeChangeHandle(val) {
      this.pageData.pageSize = val;
      this.getDataList();
    },
    // 页码分页变化
    currentChangeHandle(val) {
      this.pageData.pageIndex = val;
      this.getDataList();
    },
      //选择周期执行搜索功能
      getDataByPerid(period){
          this.searchForm.period = period ;
          this.getDataList() ;
      }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-select .el-select__tags {
  overflow: auto !important;
  //   min-height: 200px !important;
}
::v-deep.el-tag.el-tag--info {
  margin: 5px;
  border: 1px solid green;
}
</style>
